import Taro, { Component } from '@tarojs/taro'
import { View, Text, Image } from '@tarojs/components'
import { DNavBar, DLookImages } from '@/components'
import { AtList, AtListItem } from "taro-ui"
import './inventoryvehiclesdetail.scss'
import http from '@/api'
const itembg = require('../assets/people_right.png')

export default class InventoryVehiclesDetailBox extends Component {

    constructor(props) {
        super(props)
        this.state = {
            id: '',
            detailItem: {},
            companycar: {
                itemStatus: false,
                itemUrl: ''
            }
        }
    }
    componentWillMount() {
        let { carNo, id } = this.$router.params
        this.setState({
            adCarNo: carNo,
            id
        })
        this.getFormInfo(id)
    }
    getFormInfo(id) {
        http.getFormInfo(id).then(res => {
            if (!res) {
                return
            }
            let { adCarNo } = this.state
            res.carList.map(item => {
                if (item.adCarNo === adCarNo) {
                    this.setState({
                        detailItem: item
                    })
                }
            })
        })
    }

    onLookHandle(url) {
        if (window.bridge) {
            let _images = [], i = 0
            _images.push(url)
            window.bridge.callHandler('previewPhoto', { "index": i, "images": _images }, function responseCallback() { })
        } else {
            this.setState({
                companycar: {
                    ...this.state.companycar,
                    itemStatus: true,
                    itemUrl: url
                }
            })
        }
    }

    onLookItem() {
        this.setState({
            companycar: {
                ...this.state.companycar,
                itemStatus: false,
                itemUrl: ''
            }
        })
    }
    render() {
        const {
            detailItem,
            companycar
        } = this.state
        return (
            <View className='b_inventoryvehiclesdetail'>
                <DNavBar title='库融车辆'></DNavBar>
                <View className='b_inventoryvehiclesdetail__box'>
                    <View className="b_inventoryvehiclesdetail__info">
                        <View className="item_title">
                            <Text className="item_title__left">车型</Text>
                            <AtListItem title={detailItem.adCarType} className='item_title__right' arrow='right' />
                        </View>
                        <View className="item_title">
                            <Text className="item_title__left">车架号</Text>
                            <Text className="item_title__right">{detailItem.adCarNo}</Text>
                        </View>
                        <View className="item_title">
                            <Text className="item_title__left">库融金额</Text>
                            <Text className="item_title__right">{detailItem.adMoney}万</Text>
                        </View>
                        <View className="item_title">
                            <Text className="item_title__left">钥匙数量</Text>
                            <Text className="item_title__right">{detailItem.adKeys}</Text>
                        </View>
                        <View className="item_title">
                            <Text className="item_title__left">外观颜色</Text>
                            <Text className="item_title__right">{detailItem.adOutColor}</Text>
                        </View>
                        <View className="item_title">
                            <Text className="item_title__left">内饰颜色</Text>
                            <Text className="item_title__right">{detailItem.adInColor}</Text>
                        </View>
                    </View>
                </View>
                <View className='b_inventoryvehiclesdetail__images'>
                    <View className="b_inventoryvehiclesdetail__images_enterpris">
                        <View className='b_inventoryvehiclesdetail__images_enterpris_item'>
                            <Text className='item_title'>合格证照片</Text>
                            <Image src={detailItem.imageUrl} className='item_image' onClick={this.onLookHandle.bind(this, detailItem.imageUrl)}></Image>
                        </View>
                    </View>

                </View>
                <DLookImages status={companycar.itemStatus} url={companycar.itemUrl} onLookHandle={this.onLookItem.bind(this)}></DLookImages>
            </View>
        )
    }
}